#!/usr/bin/perl
#
# This is for compiling and linking C
# programs with Mesa, on Linux.
#
# usage: cogl [-g] inputfile.c
#
# changed by TLJH 21/01/10 made nicer.
# changed by TLJH 29/01/07 to use freeglut, removing refs to GLUT in /opt/common/
# changed by TLJH 05/10/04 for new GLUT dist
# changed by TLJH 30/01/02 to remove -lforms
#
# Toby Howard, 5 November 1998, version 2
#
$CC= "gcc";
$CFLAGS= "-O3 -fomit-frame-pointer -march=i486 -Wall -pipe -DFX -DXMESA ";
#
$LIB_PATHS= "-L/usr/X11/lib -L/usr/X11R6/lib ";
$OGL_LIBS= "-lglut -lGL -lGLU -lGL ";
$X_LIBS= "-lX11 -lXext -lXt -lXi ";
#
$LIBS= $OGL_LIBS . $X_LIBS . "-lm ";

local $fin, $fout;

@dirs = split(/\//,$0); $O = "$dirs[$#dirs]"; # get the program name into $O.

if (($#ARGV < 0) || ($#ARGV > 1)) { &usage; } # only one or two args

if ($#ARGV == 0) { # one arg
   $fin= $ARGV[0];
   }
elsif ($#ARGV == 1) { # two args
      if ($ARGV[0] ne "-g" ) { &usage; }
      else {
         $CFLAGS .= "-g";
         $fin= $ARGV[1];
      }
    } 

if ($fin =~ m/\.c$/) { # only accept file.c
   $fout= $fin; $fout =~ s/\.c$//; # Duff! Must be a nicer way.
   }
else { &usage; }

print "$O v5, 16/01/10: compiling $fin; output program will be: $fout\n";

local ($ret)= system("$CC $CFLAGS $HDR_PATHS $fin $LIB_PATHS $LIBS -o $fout") >> 8;
if ($ret) {die ("$O: gcc failed.\n");}

sub usage {
   print "Compiles a single C program, and links to OpenGL/GLUT.";
   print " Usage: 'cogl [-g] inputfile.c'\n";
   exit (1);
} # usage

# that's it.

